#include "StdAfx.h"
#include "UserGroupMapper.h"

namespace DBLayer{
	CUserGroupMapper::CUserGroupMapper(int)
	{
	}

	CUserGroupMapper::~CUserGroupMapper(void)
	{
	}

bool CUserGroupMapper::loadData(int type, CTinyDBInterface* m_DBIF)
{
		m_DBType = type;
		/*mysql*/
		m_MapperData.clear();
		if(type == DBTYPE_MYSQL)
		{
			try{
				sql::ResultSet * rs = (sql::ResultSet*)m_DBIF->executeSQL(std::string("SELECT GroupID, GroupName FROM usergroup")+m_filterStr );
				if(rs == NULL)
					return false;
				while (rs->next())
				{
					//process data
					std::string groupid = rs->getString("GroupID");
					std::string groupname = rs->getString("GroupName");
					std::map<std::string,std::string> tempMap;
					tempMap.insert(std::pair<std::string,std::string>("GroupID",groupid));
					tempMap.insert(std::pair<std::string,std::string>("GroupName",groupname));
					m_MapperData.push_back(tempMap);
				}
			}
			catch (sql::SQLException &e) {
				std::string err =  e.what();
				return false;
			}
		}

		/*MS SQL
		 ORACLE
		 ...*/
		return true;
}

}